package com.ksyun.campus.client.param;


import com.alibaba.fastjson.annotation.JSONField;
import com.ksyun.campus.client.domain.ReplicaData;

import java.util.Map;

/**
 * @author sxt
 * @version 1.0
 * @description TODO
 * @date 2023/8/9 21:21
 */
public class DataServerParse {

    private String ip;

    private String port;
    /**
     * 机架
     */
    private String rack;

    /**
     * 区域：北京、上海、天津
     */
    private String zone;

    private int capacity;


    private int usedCapacity;



    /**
     * 添加该节点上保存的所有文件副本信息，以fileNameId作为key
     * @return 线程安全的ConcurrentHashMap（考虑到列表可能被多个事件集中回调，从而产生并发问题）
     */
    private Map<String, ReplicaData> allReplicaDataMap;

    public DataServerParse() {
    }

    public DataServerParse(String ip, String port, String rack, String zone, int capacity, int usedCapacity) {
        this.ip = ip;
        this.port = port;
        this.rack = rack;
        this.zone = zone;
        this.capacity = capacity;
        this.usedCapacity = usedCapacity;
    }

    public DataServerParse(String ip, String port, String rack, String zone, int capacity, int usedCapacity, Map<String, ReplicaData> allReplicaDataMap) {
        this.ip = ip;
        this.port = port;
        this.rack = rack;
        this.zone = zone;
        this.capacity = capacity;
        this.usedCapacity = usedCapacity;
        this.allReplicaDataMap = allReplicaDataMap;
    }

    /**
     * 可使用容量比率
     *
     * @return
     */
    public double freeCapacityRatio() {
        return 1 - (double) usedCapacity / capacity;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getRack() {
        return rack;
    }

    public void setRack(String rack) {
        this.rack = rack;
    }

    public String getZone() {
        return zone;
    }

    public void setZone(String zone) {
        this.zone = zone;
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public int getUsedCapacity() {
        return usedCapacity;
    }

    public void setUsedCapacity(int usedCapacity) {
        this.usedCapacity = usedCapacity;
    }

    public Map<String, ReplicaData> getAllReplicaDataMap() {
        return allReplicaDataMap;
    }

    public void setAllReplicaDataMap(Map<String, ReplicaData> allReplicaDataMap) {
        this.allReplicaDataMap = allReplicaDataMap;
    }
}
